//一键处理地址异常
import { useState, useEffect } from "react";
import { Button, Typography } from "antd";
import CommonModal from "@/components/CommonModal";
import CommonTable from "@/components/CommonTable";
import { cpText } from "@/utils/utils.jsx";
import IconFont from "@/components/IconFont";

const { Paragraph } = Typography;

const ResultModal = ({ failList, handleCancel }) => {
	const [open, setOpen] = useState(false);

	const columns = [
		{
			title: (
				<div style={{ display: "flex" }}>
					<span>系统订单号</span>
					<div style={{ display: "inline-block", marginLeft: "4px" }} onClick={() => handleBatchCopy("orderSn")}>
						<IconFont type="iconcopy" style={{ fontSize: "14px", cursor: "pointer" }} />
					</div>
				</div>
			),
			dataIndex: "orderSn",
			key: "orderSn"
		},
		{
			title: (
				<div style={{ display: "flex" }}>
					<span>店铺订单号</span>
					<div style={{ display: "inline-block", marginLeft: "4px" }} onClick={() => handleBatchCopy("ecOrderSn")}>
						<IconFont type="iconcopy" style={{ fontSize: "14px", cursor: "pointer" }} />
					</div>
				</div>
			),
			dataIndex: "ecOrderSn",
			key: "ecOrderSn"
		}
	];

	useEffect(() => {
		setOpen(true);
	}, []);

	//批量复制功能
	const handleBatchCopy = type => {
		const copyText = failList
			.filter(t => t[type])
			.map(item => item[type])
			.join("\r\n");
		cpText(copyText);
	};

	//列表props
	const CommonTableProps = {
		data: failList,
		columns,
		rowKey: "orderSn",
		scroll: { y: 300 }
	};

	return (
		<CommonModal
			title="订单重算提示"
			onCancel={() => setOpen(false)}
			open={open}
			afterClose={handleCancel}
			width="558px"
			footer={
				<div>
					<Button key="close" onClick={handleCancel}>
						知道了
					</Button>
				</div>
			}
		>
			<p style={{ marginBottom: "16px" }}>
				下列订单，涉及到有组合商品的子商品订单内不完整，可能已组内拆单，这种商品不支持整个组合的重算，子商品的重算已执行，请再手动检查一下！
			</p>
			{failList.length > 0 && <CommonTable {...CommonTableProps} />}
		</CommonModal>
	);
};

export default ResultModal;
